import { FileAction } from "../../types";
import { errors } from "../errors";
import * as fs from "fs";
import * as path from "path";

let copyFile: FileAction = (filePath: string, outPath: string, projectPath: string) => {
    if (!filePath) throw errors.argumentNull("filePath");
    if (!outPath) throw errors.argumentNull("outPath");

    if (!fs.existsSync(filePath)) {
        return;
    }

    let out = filePath.replace(path.dirname(filePath), outPath);
    let outDirPath = path.resolve(out, "..");

    fs.mkdirSync(outDirPath, { recursive: true });

    fs.copyFileSync(filePath, out);
}

export default copyFile;